﻿
namespace Mulala.Cavan.Presentation.Admin.Controller
{
    using System.Collections.Generic;
    using System.Web.Mvc;
    using Mulala.Cavan.Application.MainBoundedContext.MarketModule;
    using Mulala.Cavan.Domain.MainBoundedContext.MarketModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Domain.Seedwork;
    using Mulala.Cavan.Presentation.Admin.ViewModel;
    using Mulala.Cavan.Presentation.Seedwork;

    public class MarketStatisticsController : EntityController<MarketStatistics, int, MarketStatisticsSearch, IMarketStatisticsViewModel, IMarketStatisticsAppService>, IMarketStatisticsController
    {
        private IMarketStatisticsAppService MarketStatisticsAppService { get; set; }

        public MarketStatisticsController()
        {
            this.Model = ModelFactory.CreateModel<IMarketStatisticsViewModel>();
        }

        public override string ControllerName
        {
            get {return ControllerConst.MARKETSTATISTICS; }
        }

        public override bool UseDenied
        {
            get {return true;}
        }

        [HttpGet]
        [ActionName(ActionConst.ADD)]
        public ActionResult AddMarketStatistics(int? id)
        {
            List<SelectListItem> statisticsTypeItems = new List<SelectListItem>();
            statisticsTypeItems.Add(new SelectListItem { Text = "工资", Value = MarketStatisticsIdentifier.StatisticsType.Wage.GetHashCode().ToString(), Selected = true });
            this.Model.StatisticsType = statisticsTypeItems;

            List<SelectListItem> statisticsSourceItems2 = new List<SelectListItem>();
            statisticsSourceItems2.Add(new SelectListItem { Text = "姆丫丫", Value = MarketStatisticsIdentifier.Source.Muyaya.GetHashCode().ToString(), Selected = true });
            this.Model.Source = statisticsSourceItems2;

            List<SelectListItem> statisticsYearItems3 = new List<SelectListItem>();
            statisticsYearItems3.Add(new SelectListItem { Text = "2000", Value = "2000", Selected = true });
            statisticsYearItems3.Add(new SelectListItem { Text = "2001", Value = "2001".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2002", Value = "2002".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2003", Value = "2003".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2004", Value = "2004".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2005", Value = "2005".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2006", Value = "2006".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2007", Value = "2007".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2008", Value = "2008".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2009", Value = "2009".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2010", Value = "2010".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2011", Value = "2011".ToString() });
            statisticsYearItems3.Add(new SelectListItem { Text = "2012", Value = "2012".ToString() });
            this.Model.StatisticsYear = statisticsYearItems3;
         
            MarketStatistics marketStatistics = new MarketStatistics();
            if (id.HasValue)
            {
                marketStatistics = this.AppService.GetById(id.Value);
            }
            this.Model.Item = marketStatistics; 

            return View(this.Model);
        }


        [HttpPost]
        [ActionName(ActionConst.ADD)]
        public JsonResult AddMarketStatistics(MarketStatisticsViewModel marketStatistics)
        {
            BoolGenericResult<MarketStatistics> result = null;
            MarketStatisticsViewModelConverter.Convert(marketStatistics);
            if (marketStatistics.Item.ID == 0)
            {
                result = this.AppService.Add(marketStatistics.Item);
            }
            BoolResult jsonResult = new BoolResult(result.IsSuccess, result.Messages);

            return Json(jsonResult, "application/json");
        }
    }
}